import { useEffect } from 'react'
import { useAppRoutes } from '@/routes'
import { useDispatch } from 'react-redux'
import { setTheme, AppDispatch } from '@/store'
import './App.css'

function App() {
    const dispatch = useDispatch<AppDispatch>()

    useEffect(() => {
        // 仅从localStorage读取，没有则使用默认值（false）
        const saved = localStorage.getItem('mkTheme')
        if (saved !== null) {
            dispatch(setTheme(JSON.parse(saved)))
            if (saved === 'true') {
                document.documentElement.classList.add('dark')
            } else {
                document.documentElement.classList.remove('dark')
            }
        }
    }, [dispatch])

    return (
        <>
            {useAppRoutes()}
        </>
    )
}

export default App